﻿using KFC.MonAnF;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KFC
{
    public partial class ThemPhanAnForm : Form
    {
        private string _maMonAn = null;

        public string MaMonAn
        {
            get { return _maMonAn; }
            set { _maMonAn = value; }
        }
        private int _soLuong = 0;

        public int SoLuong
        {
            get { return _soLuong; }
            set { _soLuong = value; }
        }
        private List<MonAn> dsMonAn;

        public ThemPhanAnForm(List<MonAn> l, string TenForm)
        {
            InitializeComponent();
            dsMonAn = l;
            this.Text = "Thêm phần ăn " + TenForm;
            foreach(var i in dsMonAn)
            {
                comboBoxMaMon.Items.Add(i.MaMonAn);
            }
        }

        private void comboBoxMaMon_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = comboBoxMaMon.SelectedIndex;
            textBoxTenMon.Text = dsMonAn[index].TenMonAn;
            _maMonAn = dsMonAn[index].MaMonAn;
        }

        private bool LaySoLuong()
        {
            try
            {
                _soLuong = int.Parse(textBoxSoLuong.Text);
             }
             catch
             {
                  MessageBox.Show("Nhập số lượng không đúng");
                  return false;
             }
            return true;
        }

        private void buttonHoanThanh_Click(object sender, EventArgs e)
        {
            if (!LaySoLuong())
                return;
            this.Close();
        }

        private void ThemPhanAnForm_Load(object sender, EventArgs e)
        {

        }
    }
}
